(function(){
    let page = document.querySelector('#page')
    let up = document.querySelector('.up')
    let down = document.querySelector('.down')
    let option = document.querySelectorAll('option')
    // let info = document.querySelector('.info')
    console.log(info)

    let index

    console.log(up)
    getValue()
    getInfo(index)
    console.log(index)
    down.onclick = () => {
        // console.log(1)
        up.disabled = false
        index++
        option[index - 1].selected = true
        getInfo(index)
        if (index == 14) {
            down.disabled = true
        }
    }

    up.onclick = () => {
        down.disabled = false

        index--
        option[index - 1].selected = true
        getInfo(index)

        if (index == 1) {
            up.disabled = true
        }

    }

    page.onchange = () => {
        getValue()
        getInfo(index)
        if (index == 1) {
            up.disabled = true
        } else {
            up.disabled = false
        }

        if (index == 14) {
            down.disabled = true
        } else {
            down.disabled = false

        }
    }
    info.addEventListener('click', function (e) {
        // console.log(e.target.parentNode.parentNode.parentNode.nodeName)

        let li = e.target.parentNode.parentNode.parentNode
        let id = li.getAttribute('productId')
        console.log(id)
        location.href = "./../xiangqingye.html" + id


    })
//定义一个函数 去获得option 的value 

function getValue() {
    //获取到所有的option然后循环找到被选中的哪一个
    for (let i = 0; i < option.length; i++) {
        if (option[i].selected) {
            index = option[i].value
        }


    }

    return index

}

    //发起请求
    var pl=document.querySelector(".productList")
       const xhr=new XMLHttpRequest();
       xhr.open("get","http://chst.vip:1234/api/getmoneyctrl",true);
   xhr.send(null);
   xhr.onreadystatechange = function(){
           if(xhr.readyState === 4){
               if(xhr.status === 200){
                   let res = JSON.parse(xhr.responseText);
                   console.log(res);
                   let regExp = /(?<=imgurl=)[^'"]*/;
                   let ele = "";
                   res.result.forEach(item => {
                console.log(item)
                var img = regExp.exec(item.productImg2)[0];
                                       ele += `<div productId="${item.productId}">
                                               <img src="${img}" alt="">
                                               <h5>${item.productName}</h5>
                                               <p>${item.productPinkage}</p>
                                               <span>${item.productTime}</span>
                                           </div>`
                                   });
                                   pl.innerHTML = ele;
                               }
                           }
                       }
})